
/*
移除排行榜中对应 昵称为 6951201304 的yxwl用户
*/
// 为了删除特定用户名的用户在排行榜中的位置
console.log('remove_by_nickname run!');

var redis = require('redis'),
    RDS_PORT = 6379,     //端口号
    RDS_HOST = 'ung2018.pogorockgames.com',     //服务器IP
    RDS_PWD = '1q2w3e4r5t',      //密码
    RDS_OPTS = { auth_pass: RDS_PWD },
    client = redis.createClient(RDS_PORT, RDS_HOST, RDS_OPTS);

let key = 'rank_total';
let start = 0;
let count = 1000;
const args2 = [key, "+inf", "-inf", "WITHSCORES", "LIMIT", start, count];
client.zrevrangebyscore(args2, function (rangeError, rangeResponse) {
    if (rangeError) throw rangeError;
    console.log("getRange response", rangeResponse.length);
    let c = rangeResponse.length / 2;
    let c2 = 0;
    for (let i = 0; i < c; i++) {
        let uid = rangeResponse[i * 2];
        console.log('uid', i, uid);

        client.hgetall(`user:${uid}`, function (err, data) {
            if (err != null) {
                console.log('err', err);
            } else {
                // console.log('data', data);
                if (data.nickname == '6951201304') {
                    console.log('find uid', uid);
                    c2++;
                    console.log('c2', c2);

                    // console.log(client.zrem)
                    client.zrem([key, uid]);
                }
            }
        });
    }



});
